library(cregg)
library(ggplot2)
library(ggpubr)
rm(list=ls())

#### Load data 

load("data.RData")

#### Formulas for models

f1 <- vote_choice ~ age + prof+career + gender + legeff + voteror + voterknow + smedia ## Formula
f2 <- better_pol ~ age + prof+career + gender + legeff + voteror + voterknow + smedia ## Formula
f3 <- prob_vote ~ age + prof+career + gender + legeff + voteror + voterknow + smedia ## Formula


### Run models by ideology

data5 <- data[is.na(data$ideology)==F & data$country!="Switzerland" & data$country!="Germany",]

acmes.vote_choice_all_left <- cj(data5[data5$ideology=="All left",], f1, id = ~id)
acmes.vote_choice_left <- cj(data5[data5$ideology=="Left",], f1, id = ~id)
acmes.vote_choice_center <- cj(data5[data5$ideology=="Center",], f1, id = ~id)
acmes.vote_choice_right <- cj(data5[data5$ideology=="Right",], f1, id = ~id)
acmes.vote_choice_all_right <- cj(data5[data5$ideology=="All right",], f1, id = ~id)

acmes.better_pol_all_left <- cj(data5[data5$ideology=="All left",], f2, id = ~id)
acmes.better_pol_left <- cj(data5[data5$ideology=="Left",], f2, id = ~id)
acmes.better_pol_center <- cj(data5[data5$ideology=="Center",], f2, id = ~id)
acmes.better_pol_right <- cj(data5[data5$ideology=="Right",], f2, id = ~id)
acmes.better_pol_all_right <- cj(data5[data5$ideology=="All right",], f2, id = ~id)

acmes.prob_vote_all_left <- cj(data5[data5$ideology=="All left",], f3, id = ~id)
acmes.prob_vote_left <- cj(data5[data5$ideology=="Left",], f3, id = ~id)
acmes.prob_vote_center <- cj(data5[data5$ideology=="Center",], f3, id = ~id)
acmes.prob_vote_right <- cj(data5[data5$ideology=="Right",], f3, id = ~id)
acmes.prob_vote_all_right <- cj(data5[data5$ideology=="All right",], f3, id = ~id)




mm.vote_choice_all_left <- mm(data5[data5$ideology=="All left",], f1, id = ~id)
mm.vote_choice_left <- mm(data5[data5$ideology=="Left",], f1, id = ~id)
mm.vote_choice_center <- mm(data5[data5$ideology=="Center",], f1, id = ~id)
mm.vote_choice_right <- mm(data5[data5$ideology=="Right",], f1, id = ~id)
mm.vote_choice_all_right <- mm(data5[data5$ideology=="All right",], f1, id = ~id)

mm.better_pol_all_left <- mm(data5[data5$ideology=="All left",], f2, id = ~id)
mm.better_pol_left <- mm(data5[data5$ideology=="Left",], f2, id = ~id)
mm.better_pol_center <- mm(data5[data5$ideology=="Center",], f2, id = ~id)
mm.better_pol_right <- mm(data5[data5$ideology=="Right",], f2, id = ~id)
mm.better_pol_all_right <- mm(data5[data5$ideology=="All right",], f2, id = ~id)

mm.prob_vote_all_left <- mm(data5[data5$ideology=="All left",], f3, id = ~id)
mm.prob_vote_left <- mm(data5[data5$ideology=="Left",], f3, id = ~id)
mm.prob_vote_center <- mm(data5[data5$ideology=="Center",], f3, id = ~id)
mm.prob_vote_right <- mm(data5[data5$ideology=="Right",], f3, id = ~id)
mm.prob_vote_all_right <- mm(data5[data5$ideology=="All right",], f3, id = ~id)




### Create data Figure A18

acmes.vote_choice_ideology <- rbind(acmes.vote_choice_all_left, acmes.vote_choice_left, acmes.vote_choice_center, acmes.vote_choice_right, acmes.vote_choice_all_right)
mm.vote_choice_ideology <- rbind(mm.vote_choice_all_left, mm.vote_choice_left, mm.vote_choice_center, mm.vote_choice_right, mm.vote_choice_all_right)

Ideology_data_acmes.vote_choice <- as.data.frame(list(labels = rep(c("Age", "33", "43", "53", "63", "73",
                                                          "Profession", "Buisness Person", "Farmer", "Lawyer", "Medical doctor", "Parliamentary assistant",
                                                          "Career", "Joined party 3 years ago", "Party offices in last 15 years",
                                                          "Gender", "Man", "Woman",
                                                          "Legislative Effectiveness", "Successful in parliament", "Not very successful in parliament",
                                                          "Presence in Constituency", "Rarely in constituency", "Often in constituency",
                                                          "Knowledge of voters", "Does not know voters well", "Knows voters well",
                                                          "Social Media", "Communicates regularly", "Does not communicate often"),5),
                                           labels_score = rep(c(13:30,1:12), 5),
                                           estimate = c(NA, acmes.vote_choice_ideology$estimate[1:5],
                                                        NA, acmes.vote_choice_ideology$estimate[6:10],
                                                        NA, acmes.vote_choice_ideology$estimate[11:12],
                                                        NA, acmes.vote_choice_ideology$estimate[13:14],
                                                        NA, acmes.vote_choice_ideology$estimate[15:16],
                                                        NA, acmes.vote_choice_ideology$estimate[17:18],
                                                        NA, acmes.vote_choice_ideology$estimate[19:20],
                                                        NA, acmes.vote_choice_ideology$estimate[21:22],
                                                        NA, acmes.vote_choice_ideology$estimate[22+1:5],
                                                        NA, acmes.vote_choice_ideology$estimate[22+6:10],
                                                        NA, acmes.vote_choice_ideology$estimate[22+11:12],
                                                        NA, acmes.vote_choice_ideology$estimate[22+13:14],
                                                        NA, acmes.vote_choice_ideology$estimate[22+15:16],
                                                        NA, acmes.vote_choice_ideology$estimate[22+17:18],
                                                        NA, acmes.vote_choice_ideology$estimate[22+19:20],
                                                        NA, acmes.vote_choice_ideology$estimate[22+21:22],
                                                        NA, acmes.vote_choice_ideology$estimate[44+1:5],
                                                        NA, acmes.vote_choice_ideology$estimate[44+6:10],
                                                        NA, acmes.vote_choice_ideology$estimate[44+11:12],
                                                        NA, acmes.vote_choice_ideology$estimate[44+13:14],
                                                        NA, acmes.vote_choice_ideology$estimate[44+15:16],
                                                        NA, acmes.vote_choice_ideology$estimate[44+17:18],
                                                        NA, acmes.vote_choice_ideology$estimate[44+19:20],
                                                        NA, acmes.vote_choice_ideology$estimate[44+21:22],
                                                        NA, acmes.vote_choice_ideology$estimate[66+1:5],
                                                        NA, acmes.vote_choice_ideology$estimate[66+6:10],
                                                        NA, acmes.vote_choice_ideology$estimate[66+11:12],
                                                        NA, acmes.vote_choice_ideology$estimate[66+13:14],
                                                        NA, acmes.vote_choice_ideology$estimate[66+15:16],
                                                        NA, acmes.vote_choice_ideology$estimate[66+17:18],
                                                        NA, acmes.vote_choice_ideology$estimate[66+19:20],
                                                        NA, acmes.vote_choice_ideology$estimate[66+21:22],
                                                        NA, acmes.vote_choice_ideology$estimate[88+1:5],
                                                        NA, acmes.vote_choice_ideology$estimate[88+6:10],
                                                        NA, acmes.vote_choice_ideology$estimate[88+11:12],
                                                        NA, acmes.vote_choice_ideology$estimate[88+13:14],
                                                        NA, acmes.vote_choice_ideology$estimate[88+15:16],
                                                        NA, acmes.vote_choice_ideology$estimate[88+17:18],
                                                        NA, acmes.vote_choice_ideology$estimate[88+19:20],
                                                        NA, acmes.vote_choice_ideology$estimate[88+21:22]),
                                           
                                           lower = c(NA, NA, acmes.vote_choice_ideology$lower[2:5],
                                                     NA, NA, acmes.vote_choice_ideology$lower[7:10],
                                                     NA, NA, acmes.vote_choice_ideology$lower[12],
                                                     NA, NA, acmes.vote_choice_ideology$lower[14],
                                                     NA, NA, acmes.vote_choice_ideology$lower[16],
                                                     NA, NA, acmes.vote_choice_ideology$lower[18],
                                                     NA, NA, acmes.vote_choice_ideology$lower[20],
                                                     NA, NA, acmes.vote_choice_ideology$lower[22],
                                                     NA, NA, acmes.vote_choice_ideology$lower[22+2:5],
                                                     NA, NA, acmes.vote_choice_ideology$lower[22+7:10],
                                                     NA, NA, acmes.vote_choice_ideology$lower[22+12],
                                                     NA, NA, acmes.vote_choice_ideology$lower[22+14],
                                                     NA, NA, acmes.vote_choice_ideology$lower[22+16],
                                                     NA, NA, acmes.vote_choice_ideology$lower[22+18],
                                                     NA, NA, acmes.vote_choice_ideology$lower[22+20],
                                                     NA, NA, acmes.vote_choice_ideology$lower[22+22],
                                                     NA, NA, acmes.vote_choice_ideology$lower[44+2:5],
                                                     NA, NA, acmes.vote_choice_ideology$lower[44+7:10],
                                                     NA, NA, acmes.vote_choice_ideology$lower[44+12],
                                                     NA, NA, acmes.vote_choice_ideology$lower[44+14],
                                                     NA, NA, acmes.vote_choice_ideology$lower[44+16],
                                                     NA, NA, acmes.vote_choice_ideology$lower[44+18],
                                                     NA, NA, acmes.vote_choice_ideology$lower[44+20],
                                                     NA, NA, acmes.vote_choice_ideology$lower[44+22],
                                                     NA, NA, acmes.vote_choice_ideology$lower[66+2:5],
                                                     NA, NA, acmes.vote_choice_ideology$lower[66+7:10],
                                                     NA, NA, acmes.vote_choice_ideology$lower[66+12],
                                                     NA, NA, acmes.vote_choice_ideology$lower[66+14],
                                                     NA, NA, acmes.vote_choice_ideology$lower[66+16],
                                                     NA, NA, acmes.vote_choice_ideology$lower[66+18],
                                                     NA, NA, acmes.vote_choice_ideology$lower[66+20],
                                                     NA, NA, acmes.vote_choice_ideology$lower[66+22],
                                                     NA, NA, acmes.vote_choice_ideology$lower[88+2:5],
                                                     NA, NA, acmes.vote_choice_ideology$lower[88+7:10],
                                                     NA, NA, acmes.vote_choice_ideology$lower[88+12],
                                                     NA, NA, acmes.vote_choice_ideology$lower[88+14],
                                                     NA, NA, acmes.vote_choice_ideology$lower[88+16],
                                                     NA, NA, acmes.vote_choice_ideology$lower[88+18],
                                                     NA, NA, acmes.vote_choice_ideology$lower[88+20],
                                                     NA, NA, acmes.vote_choice_ideology$lower[88+22]),
                                           upper = c(NA, NA, acmes.vote_choice_ideology$upper[2:5],
                                                     NA, NA, acmes.vote_choice_ideology$upper[7:10],
                                                     NA, NA, acmes.vote_choice_ideology$upper[12],
                                                     NA, NA, acmes.vote_choice_ideology$upper[14],
                                                     NA, NA, acmes.vote_choice_ideology$upper[16],
                                                     NA, NA, acmes.vote_choice_ideology$upper[18],
                                                     NA, NA, acmes.vote_choice_ideology$upper[20],
                                                     NA, NA, acmes.vote_choice_ideology$upper[22],
                                                     NA, NA, acmes.vote_choice_ideology$upper[22+2:5],
                                                     NA, NA, acmes.vote_choice_ideology$upper[22+7:10],
                                                     NA, NA, acmes.vote_choice_ideology$upper[22+12],
                                                     NA, NA, acmes.vote_choice_ideology$upper[22+14],
                                                     NA, NA, acmes.vote_choice_ideology$upper[22+16],
                                                     NA, NA, acmes.vote_choice_ideology$upper[22+18],
                                                     NA, NA, acmes.vote_choice_ideology$upper[22+20],
                                                     NA, NA, acmes.vote_choice_ideology$upper[22+22],
                                                     NA, NA, acmes.vote_choice_ideology$upper[44+2:5],
                                                     NA, NA, acmes.vote_choice_ideology$upper[44+7:10],
                                                     NA, NA, acmes.vote_choice_ideology$upper[44+12],
                                                     NA, NA, acmes.vote_choice_ideology$upper[44+14],
                                                     NA, NA, acmes.vote_choice_ideology$upper[44+16],
                                                     NA, NA, acmes.vote_choice_ideology$upper[44+18],
                                                     NA, NA, acmes.vote_choice_ideology$upper[44+20],
                                                     NA, NA, acmes.vote_choice_ideology$upper[44+22],
                                                     NA, NA, acmes.vote_choice_ideology$upper[66+2:5],
                                                     NA, NA, acmes.vote_choice_ideology$upper[66+7:10],
                                                     NA, NA, acmes.vote_choice_ideology$upper[66+12],
                                                     NA, NA, acmes.vote_choice_ideology$upper[66+14],
                                                     NA, NA, acmes.vote_choice_ideology$upper[66+16],
                                                     NA, NA, acmes.vote_choice_ideology$upper[66+18],
                                                     NA, NA, acmes.vote_choice_ideology$upper[66+20],
                                                     NA, NA, acmes.vote_choice_ideology$upper[66+22],
                                                     NA, NA, acmes.vote_choice_ideology$upper[88+2:5],
                                                     NA, NA, acmes.vote_choice_ideology$upper[88+7:10],
                                                     NA, NA, acmes.vote_choice_ideology$upper[88+12],
                                                     NA, NA, acmes.vote_choice_ideology$upper[88+14],
                                                     NA, NA, acmes.vote_choice_ideology$upper[88+16],
                                                     NA, NA, acmes.vote_choice_ideology$upper[88+18],
                                                     NA, NA, acmes.vote_choice_ideology$upper[88+20],
                                                     NA, NA, acmes.vote_choice_ideology$upper[88+22]),
                                           Ideology = rep(c("All left", "Left", "Center", "Right", "All right"), each=30),
                                           Ideology_score = rep(c(0:4), each=30)))



Ideology_data_mm.vote_choice <- as.data.frame(list(labels = rep(c("Age", "33", "43", "53", "63", "73",
                                                       "Profession", "Buisness Person", "Farmer", "Lawyer", "Medical doctor", "Parliamentary assistant",
                                                       "Career", "Joined party 3 years ago", "Party offices in last 15 years",
                                                       "Gender", "Man", "Woman",
                                                       "Legislative Effectiveness", "Successful in parliament", "Not very successful in parliament",
                                                       "Presence in Constituency", "Rarely in constituency", "Often in constituency",
                                                       "Knowledge of voters", "Does not know voters well", "Knows voters well",
                                                       "Social Media", "Communicates regularly", "Does not communicate often"),5),
                                        labels_score = rep(c(13:30,1:12), 5),
                                        estimate = c(NA, mm.vote_choice_ideology$estimate[1:5],
                                                     NA, mm.vote_choice_ideology$estimate[6:10],
                                                     NA, mm.vote_choice_ideology$estimate[11:12],
                                                     NA, mm.vote_choice_ideology$estimate[13:14],
                                                     NA, mm.vote_choice_ideology$estimate[15:16],
                                                     NA, mm.vote_choice_ideology$estimate[17:18],
                                                     NA, mm.vote_choice_ideology$estimate[19:20],
                                                     NA, mm.vote_choice_ideology$estimate[21:22],
                                                     NA, mm.vote_choice_ideology$estimate[22+1:5],
                                                     NA, mm.vote_choice_ideology$estimate[22+6:10],
                                                     NA, mm.vote_choice_ideology$estimate[22+11:12],
                                                     NA, mm.vote_choice_ideology$estimate[22+13:14],
                                                     NA, mm.vote_choice_ideology$estimate[22+15:16],
                                                     NA, mm.vote_choice_ideology$estimate[22+17:18],
                                                     NA, mm.vote_choice_ideology$estimate[22+19:20],
                                                     NA, mm.vote_choice_ideology$estimate[22+21:22],
                                                     NA, mm.vote_choice_ideology$estimate[44+1:5],
                                                     NA, mm.vote_choice_ideology$estimate[44+6:10],
                                                     NA, mm.vote_choice_ideology$estimate[44+11:12],
                                                     NA, mm.vote_choice_ideology$estimate[44+13:14],
                                                     NA, mm.vote_choice_ideology$estimate[44+15:16],
                                                     NA, mm.vote_choice_ideology$estimate[44+17:18],
                                                     NA, mm.vote_choice_ideology$estimate[44+19:20],
                                                     NA, mm.vote_choice_ideology$estimate[44+21:22],
                                                     NA, mm.vote_choice_ideology$estimate[66+1:5],
                                                     NA, mm.vote_choice_ideology$estimate[66+6:10],
                                                     NA, mm.vote_choice_ideology$estimate[66+11:12],
                                                     NA, mm.vote_choice_ideology$estimate[66+13:14],
                                                     NA, mm.vote_choice_ideology$estimate[66+15:16],
                                                     NA, mm.vote_choice_ideology$estimate[66+17:18],
                                                     NA, mm.vote_choice_ideology$estimate[66+19:20],
                                                     NA, mm.vote_choice_ideology$estimate[66+21:22],
                                                     NA, mm.vote_choice_ideology$estimate[88+1:5],
                                                     NA, mm.vote_choice_ideology$estimate[88+6:10],
                                                     NA, mm.vote_choice_ideology$estimate[88+11:12],
                                                     NA, mm.vote_choice_ideology$estimate[88+13:14],
                                                     NA, mm.vote_choice_ideology$estimate[88+15:16],
                                                     NA, mm.vote_choice_ideology$estimate[88+17:18],
                                                     NA, mm.vote_choice_ideology$estimate[88+19:20],
                                                     NA, mm.vote_choice_ideology$estimate[88+21:22]),
                                        
                                        lower = c(NA, mm.vote_choice_ideology$lower[1:5],
                                                  NA, mm.vote_choice_ideology$lower[6:10],
                                                  NA, mm.vote_choice_ideology$lower[11:12],
                                                  NA, mm.vote_choice_ideology$lower[13:14],
                                                  NA, mm.vote_choice_ideology$lower[15:16],
                                                  NA, mm.vote_choice_ideology$lower[17:18],
                                                  NA, mm.vote_choice_ideology$lower[19:20],
                                                  NA, mm.vote_choice_ideology$lower[21:22],
                                                  NA, mm.vote_choice_ideology$lower[22+1:5],
                                                  NA, mm.vote_choice_ideology$lower[22+6:10],
                                                  NA, mm.vote_choice_ideology$lower[22+11:12],
                                                  NA, mm.vote_choice_ideology$lower[22+13:14],
                                                  NA, mm.vote_choice_ideology$lower[22+15:16],
                                                  NA, mm.vote_choice_ideology$lower[22+17:18],
                                                  NA, mm.vote_choice_ideology$lower[22+19:20],
                                                  NA, mm.vote_choice_ideology$lower[22+21:22],
                                                  NA, mm.vote_choice_ideology$lower[44+1:5],
                                                  NA, mm.vote_choice_ideology$lower[44+6:10],
                                                  NA, mm.vote_choice_ideology$lower[44+11:12],
                                                  NA, mm.vote_choice_ideology$lower[44+13:14],
                                                  NA, mm.vote_choice_ideology$lower[44+15:16],
                                                  NA, mm.vote_choice_ideology$lower[44+17:18],
                                                  NA, mm.vote_choice_ideology$lower[44+19:20],
                                                  NA, mm.vote_choice_ideology$lower[44+21:22],
                                                  NA, mm.vote_choice_ideology$lower[66+1:5],
                                                  NA, mm.vote_choice_ideology$lower[66+6:10],
                                                  NA, mm.vote_choice_ideology$lower[66+11:12],
                                                  NA, mm.vote_choice_ideology$lower[66+13:14],
                                                  NA, mm.vote_choice_ideology$lower[66+15:16],
                                                  NA, mm.vote_choice_ideology$lower[66+17:18],
                                                  NA, mm.vote_choice_ideology$lower[66+19:20],
                                                  NA, mm.vote_choice_ideology$lower[66+21:22],
                                                  NA, mm.vote_choice_ideology$lower[88+1:5],
                                                  NA, mm.vote_choice_ideology$lower[88+6:10],
                                                  NA, mm.vote_choice_ideology$lower[88+11:12],
                                                  NA, mm.vote_choice_ideology$lower[88+13:14],
                                                  NA, mm.vote_choice_ideology$lower[88+15:16],
                                                  NA, mm.vote_choice_ideology$lower[88+17:18],
                                                  NA, mm.vote_choice_ideology$lower[88+19:20],
                                                  NA, mm.vote_choice_ideology$lower[88+21:22]),
                                        upper = c(NA, mm.vote_choice_ideology$upper[1:5],
                                                  NA, mm.vote_choice_ideology$upper[6:10],
                                                  NA, mm.vote_choice_ideology$upper[11:12],
                                                  NA, mm.vote_choice_ideology$upper[13:14],
                                                  NA, mm.vote_choice_ideology$upper[15:16],
                                                  NA, mm.vote_choice_ideology$upper[17:18],
                                                  NA, mm.vote_choice_ideology$upper[19:20],
                                                  NA, mm.vote_choice_ideology$upper[21:22],
                                                  NA, mm.vote_choice_ideology$upper[22+1:5],
                                                  NA, mm.vote_choice_ideology$upper[22+6:10],
                                                  NA, mm.vote_choice_ideology$upper[22+11:12],
                                                  NA, mm.vote_choice_ideology$upper[22+13:14],
                                                  NA, mm.vote_choice_ideology$upper[22+15:16],
                                                  NA, mm.vote_choice_ideology$upper[22+17:18],
                                                  NA, mm.vote_choice_ideology$upper[22+19:20],
                                                  NA, mm.vote_choice_ideology$upper[22+21:22],
                                                  NA, mm.vote_choice_ideology$upper[44+1:5],
                                                  NA, mm.vote_choice_ideology$upper[44+6:10],
                                                  NA, mm.vote_choice_ideology$upper[44+11:12],
                                                  NA, mm.vote_choice_ideology$upper[44+13:14],
                                                  NA, mm.vote_choice_ideology$upper[44+15:16],
                                                  NA, mm.vote_choice_ideology$upper[44+17:18],
                                                  NA, mm.vote_choice_ideology$upper[44+19:20],
                                                  NA, mm.vote_choice_ideology$upper[44+21:22],
                                                  NA, mm.vote_choice_ideology$upper[66+1:5],
                                                  NA, mm.vote_choice_ideology$upper[66+6:10],
                                                  NA, mm.vote_choice_ideology$upper[66+11:12],
                                                  NA, mm.vote_choice_ideology$upper[66+13:14],
                                                  NA, mm.vote_choice_ideology$upper[66+15:16],
                                                  NA, mm.vote_choice_ideology$upper[66+17:18],
                                                  NA, mm.vote_choice_ideology$upper[66+19:20],
                                                  NA, mm.vote_choice_ideology$upper[66+21:22],
                                                  NA, mm.vote_choice_ideology$upper[88+1:5],
                                                  NA, mm.vote_choice_ideology$upper[88+6:10],
                                                  NA, mm.vote_choice_ideology$upper[88+11:12],
                                                  NA, mm.vote_choice_ideology$upper[88+13:14],
                                                  NA, mm.vote_choice_ideology$upper[88+15:16],
                                                  NA, mm.vote_choice_ideology$upper[88+17:18],
                                                  NA, mm.vote_choice_ideology$upper[88+19:20],
                                                  NA, mm.vote_choice_ideology$upper[88+21:22]),
                                        Ideology = rep(c("All left", "Left", "Center", "Right", "All right"), each=30),
                                        Ideology_score = rep(c(0:4), each=30)))


Ideology_data_acmes.vote_choice$Ideology <- factor(Ideology_data_acmes.vote_choice$Ideology,
                                        levels = c("All left", "Left", "Center", "Right", "All right"))

Ideology_data_mm.vote_choice$Ideology <- factor(Ideology_data_mm.vote_choice$Ideology,
                                     levels = c("All left", "Left", "Center", "Right", "All right"))



Ideology_data_acmes.vote_choice$type <- "Acmes"
Ideology_data_mm.vote_choice$type <- "Marginal Means"

Ideology_data_acmes.vote_choice$labels_score2 <- as.numeric(paste0(Ideology_data_acmes.vote_choice$labels_score, ".", Ideology_data_acmes.vote_choice$Ideology_score))
Ideology_data_mm.vote_choice$labels_score2 <- as.numeric(paste0(Ideology_data_mm.vote_choice$labels_score, ".", Ideology_data_mm.vote_choice$Ideology_score))


## Create data Figure A19




acmes.better_pol_ideology <- rbind(acmes.better_pol_all_left, acmes.better_pol_left, acmes.better_pol_center, acmes.better_pol_right, acmes.better_pol_all_right)
mm.better_pol_ideology <- rbind(mm.better_pol_all_left, mm.better_pol_left, mm.better_pol_center, mm.better_pol_right, mm.better_pol_all_right)



Ideology_data_acmes.better_pol <- as.data.frame(list(labels = rep(c("Age", "33", "43", "53", "63", "73",
                                                                    "Profession", "Buisness Person", "Farmer", "Lawyer", "Medical doctor", "Parliamentary assistant",
                                                                    "Career", "Joined party 3 years ago", "Party offices in last 15 years",
                                                                    "Gender", "Man", "Woman",
                                                                    "Legislative Effectiveness", "Successful in parliament", "Not very successful in parliament",
                                                                    "Presence in Constituency", "Rarely in constituency", "Often in constituency",
                                                                    "Knowledge of voters", "Does not know voters well", "Knows voters well",
                                                                    "Social Media", "Communicates regularly", "Does not communicate often"),5),
                                                     labels_score = rep(c(13:30,1:12), 5),
                                                     estimate = c(NA, acmes.better_pol_ideology$estimate[1:5],
                                                                  NA, acmes.better_pol_ideology$estimate[6:10],
                                                                  NA, acmes.better_pol_ideology$estimate[11:12],
                                                                  NA, acmes.better_pol_ideology$estimate[13:14],
                                                                  NA, acmes.better_pol_ideology$estimate[15:16],
                                                                  NA, acmes.better_pol_ideology$estimate[17:18],
                                                                  NA, acmes.better_pol_ideology$estimate[19:20],
                                                                  NA, acmes.better_pol_ideology$estimate[21:22],
                                                                  NA, acmes.better_pol_ideology$estimate[22+1:5],
                                                                  NA, acmes.better_pol_ideology$estimate[22+6:10],
                                                                  NA, acmes.better_pol_ideology$estimate[22+11:12],
                                                                  NA, acmes.better_pol_ideology$estimate[22+13:14],
                                                                  NA, acmes.better_pol_ideology$estimate[22+15:16],
                                                                  NA, acmes.better_pol_ideology$estimate[22+17:18],
                                                                  NA, acmes.better_pol_ideology$estimate[22+19:20],
                                                                  NA, acmes.better_pol_ideology$estimate[22+21:22],
                                                                  NA, acmes.better_pol_ideology$estimate[44+1:5],
                                                                  NA, acmes.better_pol_ideology$estimate[44+6:10],
                                                                  NA, acmes.better_pol_ideology$estimate[44+11:12],
                                                                  NA, acmes.better_pol_ideology$estimate[44+13:14],
                                                                  NA, acmes.better_pol_ideology$estimate[44+15:16],
                                                                  NA, acmes.better_pol_ideology$estimate[44+17:18],
                                                                  NA, acmes.better_pol_ideology$estimate[44+19:20],
                                                                  NA, acmes.better_pol_ideology$estimate[44+21:22],
                                                                  NA, acmes.better_pol_ideology$estimate[66+1:5],
                                                                  NA, acmes.better_pol_ideology$estimate[66+6:10],
                                                                  NA, acmes.better_pol_ideology$estimate[66+11:12],
                                                                  NA, acmes.better_pol_ideology$estimate[66+13:14],
                                                                  NA, acmes.better_pol_ideology$estimate[66+15:16],
                                                                  NA, acmes.better_pol_ideology$estimate[66+17:18],
                                                                  NA, acmes.better_pol_ideology$estimate[66+19:20],
                                                                  NA, acmes.better_pol_ideology$estimate[66+21:22],
                                                                  NA, acmes.better_pol_ideology$estimate[88+1:5],
                                                                  NA, acmes.better_pol_ideology$estimate[88+6:10],
                                                                  NA, acmes.better_pol_ideology$estimate[88+11:12],
                                                                  NA, acmes.better_pol_ideology$estimate[88+13:14],
                                                                  NA, acmes.better_pol_ideology$estimate[88+15:16],
                                                                  NA, acmes.better_pol_ideology$estimate[88+17:18],
                                                                  NA, acmes.better_pol_ideology$estimate[88+19:20],
                                                                  NA, acmes.better_pol_ideology$estimate[88+21:22]),
                                                     
                                                     lower = c(NA, NA, acmes.better_pol_ideology$lower[2:5],
                                                               NA, NA, acmes.better_pol_ideology$lower[7:10],
                                                               NA, NA, acmes.better_pol_ideology$lower[12],
                                                               NA, NA, acmes.better_pol_ideology$lower[14],
                                                               NA, NA, acmes.better_pol_ideology$lower[16],
                                                               NA, NA, acmes.better_pol_ideology$lower[18],
                                                               NA, NA, acmes.better_pol_ideology$lower[20],
                                                               NA, NA, acmes.better_pol_ideology$lower[22],
                                                               NA, NA, acmes.better_pol_ideology$lower[22+2:5],
                                                               NA, NA, acmes.better_pol_ideology$lower[22+7:10],
                                                               NA, NA, acmes.better_pol_ideology$lower[22+12],
                                                               NA, NA, acmes.better_pol_ideology$lower[22+14],
                                                               NA, NA, acmes.better_pol_ideology$lower[22+16],
                                                               NA, NA, acmes.better_pol_ideology$lower[22+18],
                                                               NA, NA, acmes.better_pol_ideology$lower[22+20],
                                                               NA, NA, acmes.better_pol_ideology$lower[22+22],
                                                               NA, NA, acmes.better_pol_ideology$lower[44+2:5],
                                                               NA, NA, acmes.better_pol_ideology$lower[44+7:10],
                                                               NA, NA, acmes.better_pol_ideology$lower[44+12],
                                                               NA, NA, acmes.better_pol_ideology$lower[44+14],
                                                               NA, NA, acmes.better_pol_ideology$lower[44+16],
                                                               NA, NA, acmes.better_pol_ideology$lower[44+18],
                                                               NA, NA, acmes.better_pol_ideology$lower[44+20],
                                                               NA, NA, acmes.better_pol_ideology$lower[44+22],
                                                               NA, NA, acmes.better_pol_ideology$lower[66+2:5],
                                                               NA, NA, acmes.better_pol_ideology$lower[66+7:10],
                                                               NA, NA, acmes.better_pol_ideology$lower[66+12],
                                                               NA, NA, acmes.better_pol_ideology$lower[66+14],
                                                               NA, NA, acmes.better_pol_ideology$lower[66+16],
                                                               NA, NA, acmes.better_pol_ideology$lower[66+18],
                                                               NA, NA, acmes.better_pol_ideology$lower[66+20],
                                                               NA, NA, acmes.better_pol_ideology$lower[66+22],
                                                               NA, NA, acmes.better_pol_ideology$lower[88+2:5],
                                                               NA, NA, acmes.better_pol_ideology$lower[88+7:10],
                                                               NA, NA, acmes.better_pol_ideology$lower[88+12],
                                                               NA, NA, acmes.better_pol_ideology$lower[88+14],
                                                               NA, NA, acmes.better_pol_ideology$lower[88+16],
                                                               NA, NA, acmes.better_pol_ideology$lower[88+18],
                                                               NA, NA, acmes.better_pol_ideology$lower[88+20],
                                                               NA, NA, acmes.better_pol_ideology$lower[88+22]),
                                                     upper = c(NA, NA, acmes.better_pol_ideology$upper[2:5],
                                                               NA, NA, acmes.better_pol_ideology$upper[7:10],
                                                               NA, NA, acmes.better_pol_ideology$upper[12],
                                                               NA, NA, acmes.better_pol_ideology$upper[14],
                                                               NA, NA, acmes.better_pol_ideology$upper[16],
                                                               NA, NA, acmes.better_pol_ideology$upper[18],
                                                               NA, NA, acmes.better_pol_ideology$upper[20],
                                                               NA, NA, acmes.better_pol_ideology$upper[22],
                                                               NA, NA, acmes.better_pol_ideology$upper[22+2:5],
                                                               NA, NA, acmes.better_pol_ideology$upper[22+7:10],
                                                               NA, NA, acmes.better_pol_ideology$upper[22+12],
                                                               NA, NA, acmes.better_pol_ideology$upper[22+14],
                                                               NA, NA, acmes.better_pol_ideology$upper[22+16],
                                                               NA, NA, acmes.better_pol_ideology$upper[22+18],
                                                               NA, NA, acmes.better_pol_ideology$upper[22+20],
                                                               NA, NA, acmes.better_pol_ideology$upper[22+22],
                                                               NA, NA, acmes.better_pol_ideology$upper[44+2:5],
                                                               NA, NA, acmes.better_pol_ideology$upper[44+7:10],
                                                               NA, NA, acmes.better_pol_ideology$upper[44+12],
                                                               NA, NA, acmes.better_pol_ideology$upper[44+14],
                                                               NA, NA, acmes.better_pol_ideology$upper[44+16],
                                                               NA, NA, acmes.better_pol_ideology$upper[44+18],
                                                               NA, NA, acmes.better_pol_ideology$upper[44+20],
                                                               NA, NA, acmes.better_pol_ideology$upper[44+22],
                                                               NA, NA, acmes.better_pol_ideology$upper[66+2:5],
                                                               NA, NA, acmes.better_pol_ideology$upper[66+7:10],
                                                               NA, NA, acmes.better_pol_ideology$upper[66+12],
                                                               NA, NA, acmes.better_pol_ideology$upper[66+14],
                                                               NA, NA, acmes.better_pol_ideology$upper[66+16],
                                                               NA, NA, acmes.better_pol_ideology$upper[66+18],
                                                               NA, NA, acmes.better_pol_ideology$upper[66+20],
                                                               NA, NA, acmes.better_pol_ideology$upper[66+22],
                                                               NA, NA, acmes.better_pol_ideology$upper[88+2:5],
                                                               NA, NA, acmes.better_pol_ideology$upper[88+7:10],
                                                               NA, NA, acmes.better_pol_ideology$upper[88+12],
                                                               NA, NA, acmes.better_pol_ideology$upper[88+14],
                                                               NA, NA, acmes.better_pol_ideology$upper[88+16],
                                                               NA, NA, acmes.better_pol_ideology$upper[88+18],
                                                               NA, NA, acmes.better_pol_ideology$upper[88+20],
                                                               NA, NA, acmes.better_pol_ideology$upper[88+22]),
                                                     Ideology = rep(c("All left", "Left", "Center", "Right", "All right"), each=30),
                                                     Ideology_score = rep(c(0:4), each=30)))



Ideology_data_mm.better_pol <- as.data.frame(list(labels = rep(c("Age", "33", "43", "53", "63", "73",
                                                                 "Profession", "Buisness Person", "Farmer", "Lawyer", "Medical doctor", "Parliamentary assistant",
                                                                 "Career", "Joined party 3 years ago", "Party offices in last 15 years",
                                                                 "Gender", "Man", "Woman",
                                                                 "Legislative Effectiveness", "Successful in parliament", "Not very successful in parliament",
                                                                 "Presence in Constituency", "Rarely in constituency", "Often in constituency",
                                                                 "Knowledge of voters", "Does not know voters well", "Knows voters well",
                                                                 "Social Media", "Communicates regularly", "Does not communicate often"),5),
                                                  labels_score = rep(c(13:30,1:12), 5),
                                                  estimate = c(NA, mm.better_pol_ideology$estimate[1:5],
                                                               NA, mm.better_pol_ideology$estimate[6:10],
                                                               NA, mm.better_pol_ideology$estimate[11:12],
                                                               NA, mm.better_pol_ideology$estimate[13:14],
                                                               NA, mm.better_pol_ideology$estimate[15:16],
                                                               NA, mm.better_pol_ideology$estimate[17:18],
                                                               NA, mm.better_pol_ideology$estimate[19:20],
                                                               NA, mm.better_pol_ideology$estimate[21:22],
                                                               NA, mm.better_pol_ideology$estimate[22+1:5],
                                                               NA, mm.better_pol_ideology$estimate[22+6:10],
                                                               NA, mm.better_pol_ideology$estimate[22+11:12],
                                                               NA, mm.better_pol_ideology$estimate[22+13:14],
                                                               NA, mm.better_pol_ideology$estimate[22+15:16],
                                                               NA, mm.better_pol_ideology$estimate[22+17:18],
                                                               NA, mm.better_pol_ideology$estimate[22+19:20],
                                                               NA, mm.better_pol_ideology$estimate[22+21:22],
                                                               NA, mm.better_pol_ideology$estimate[44+1:5],
                                                               NA, mm.better_pol_ideology$estimate[44+6:10],
                                                               NA, mm.better_pol_ideology$estimate[44+11:12],
                                                               NA, mm.better_pol_ideology$estimate[44+13:14],
                                                               NA, mm.better_pol_ideology$estimate[44+15:16],
                                                               NA, mm.better_pol_ideology$estimate[44+17:18],
                                                               NA, mm.better_pol_ideology$estimate[44+19:20],
                                                               NA, mm.better_pol_ideology$estimate[44+21:22],
                                                               NA, mm.better_pol_ideology$estimate[66+1:5],
                                                               NA, mm.better_pol_ideology$estimate[66+6:10],
                                                               NA, mm.better_pol_ideology$estimate[66+11:12],
                                                               NA, mm.better_pol_ideology$estimate[66+13:14],
                                                               NA, mm.better_pol_ideology$estimate[66+15:16],
                                                               NA, mm.better_pol_ideology$estimate[66+17:18],
                                                               NA, mm.better_pol_ideology$estimate[66+19:20],
                                                               NA, mm.better_pol_ideology$estimate[66+21:22],
                                                               NA, mm.better_pol_ideology$estimate[88+1:5],
                                                               NA, mm.better_pol_ideology$estimate[88+6:10],
                                                               NA, mm.better_pol_ideology$estimate[88+11:12],
                                                               NA, mm.better_pol_ideology$estimate[88+13:14],
                                                               NA, mm.better_pol_ideology$estimate[88+15:16],
                                                               NA, mm.better_pol_ideology$estimate[88+17:18],
                                                               NA, mm.better_pol_ideology$estimate[88+19:20],
                                                               NA, mm.better_pol_ideology$estimate[88+21:22]),
                                                  
                                                  lower = c(NA, mm.better_pol_ideology$lower[1:5],
                                                            NA, mm.better_pol_ideology$lower[6:10],
                                                            NA, mm.better_pol_ideology$lower[11:12],
                                                            NA, mm.better_pol_ideology$lower[13:14],
                                                            NA, mm.better_pol_ideology$lower[15:16],
                                                            NA, mm.better_pol_ideology$lower[17:18],
                                                            NA, mm.better_pol_ideology$lower[19:20],
                                                            NA, mm.better_pol_ideology$lower[21:22],
                                                            NA, mm.better_pol_ideology$lower[22+1:5],
                                                            NA, mm.better_pol_ideology$lower[22+6:10],
                                                            NA, mm.better_pol_ideology$lower[22+11:12],
                                                            NA, mm.better_pol_ideology$lower[22+13:14],
                                                            NA, mm.better_pol_ideology$lower[22+15:16],
                                                            NA, mm.better_pol_ideology$lower[22+17:18],
                                                            NA, mm.better_pol_ideology$lower[22+19:20],
                                                            NA, mm.better_pol_ideology$lower[22+21:22],
                                                            NA, mm.better_pol_ideology$lower[44+1:5],
                                                            NA, mm.better_pol_ideology$lower[44+6:10],
                                                            NA, mm.better_pol_ideology$lower[44+11:12],
                                                            NA, mm.better_pol_ideology$lower[44+13:14],
                                                            NA, mm.better_pol_ideology$lower[44+15:16],
                                                            NA, mm.better_pol_ideology$lower[44+17:18],
                                                            NA, mm.better_pol_ideology$lower[44+19:20],
                                                            NA, mm.better_pol_ideology$lower[44+21:22],
                                                            NA, mm.better_pol_ideology$lower[66+1:5],
                                                            NA, mm.better_pol_ideology$lower[66+6:10],
                                                            NA, mm.better_pol_ideology$lower[66+11:12],
                                                            NA, mm.better_pol_ideology$lower[66+13:14],
                                                            NA, mm.better_pol_ideology$lower[66+15:16],
                                                            NA, mm.better_pol_ideology$lower[66+17:18],
                                                            NA, mm.better_pol_ideology$lower[66+19:20],
                                                            NA, mm.better_pol_ideology$lower[66+21:22],
                                                            NA, mm.better_pol_ideology$lower[88+1:5],
                                                            NA, mm.better_pol_ideology$lower[88+6:10],
                                                            NA, mm.better_pol_ideology$lower[88+11:12],
                                                            NA, mm.better_pol_ideology$lower[88+13:14],
                                                            NA, mm.better_pol_ideology$lower[88+15:16],
                                                            NA, mm.better_pol_ideology$lower[88+17:18],
                                                            NA, mm.better_pol_ideology$lower[88+19:20],
                                                            NA, mm.better_pol_ideology$lower[88+21:22]),
                                                  upper = c(NA, mm.better_pol_ideology$upper[1:5],
                                                            NA, mm.better_pol_ideology$upper[6:10],
                                                            NA, mm.better_pol_ideology$upper[11:12],
                                                            NA, mm.better_pol_ideology$upper[13:14],
                                                            NA, mm.better_pol_ideology$upper[15:16],
                                                            NA, mm.better_pol_ideology$upper[17:18],
                                                            NA, mm.better_pol_ideology$upper[19:20],
                                                            NA, mm.better_pol_ideology$upper[21:22],
                                                            NA, mm.better_pol_ideology$upper[22+1:5],
                                                            NA, mm.better_pol_ideology$upper[22+6:10],
                                                            NA, mm.better_pol_ideology$upper[22+11:12],
                                                            NA, mm.better_pol_ideology$upper[22+13:14],
                                                            NA, mm.better_pol_ideology$upper[22+15:16],
                                                            NA, mm.better_pol_ideology$upper[22+17:18],
                                                            NA, mm.better_pol_ideology$upper[22+19:20],
                                                            NA, mm.better_pol_ideology$upper[22+21:22],
                                                            NA, mm.better_pol_ideology$upper[44+1:5],
                                                            NA, mm.better_pol_ideology$upper[44+6:10],
                                                            NA, mm.better_pol_ideology$upper[44+11:12],
                                                            NA, mm.better_pol_ideology$upper[44+13:14],
                                                            NA, mm.better_pol_ideology$upper[44+15:16],
                                                            NA, mm.better_pol_ideology$upper[44+17:18],
                                                            NA, mm.better_pol_ideology$upper[44+19:20],
                                                            NA, mm.better_pol_ideology$upper[44+21:22],
                                                            NA, mm.better_pol_ideology$upper[66+1:5],
                                                            NA, mm.better_pol_ideology$upper[66+6:10],
                                                            NA, mm.better_pol_ideology$upper[66+11:12],
                                                            NA, mm.better_pol_ideology$upper[66+13:14],
                                                            NA, mm.better_pol_ideology$upper[66+15:16],
                                                            NA, mm.better_pol_ideology$upper[66+17:18],
                                                            NA, mm.better_pol_ideology$upper[66+19:20],
                                                            NA, mm.better_pol_ideology$upper[66+21:22],
                                                            NA, mm.better_pol_ideology$upper[88+1:5],
                                                            NA, mm.better_pol_ideology$upper[88+6:10],
                                                            NA, mm.better_pol_ideology$upper[88+11:12],
                                                            NA, mm.better_pol_ideology$upper[88+13:14],
                                                            NA, mm.better_pol_ideology$upper[88+15:16],
                                                            NA, mm.better_pol_ideology$upper[88+17:18],
                                                            NA, mm.better_pol_ideology$upper[88+19:20],
                                                            NA, mm.better_pol_ideology$upper[88+21:22]),
                                                  Ideology = rep(c("All left", "Left", "Center", "Right", "All right"), each=30),
                                                  Ideology_score = rep(c(0:4), each=30)))


Ideology_data_acmes.better_pol$Ideology <- factor(Ideology_data_acmes.better_pol$Ideology,
                                                  levels = c("All left", "Left", "Center", "Right", "All right"))

Ideology_data_mm.better_pol$Ideology <- factor(Ideology_data_mm.better_pol$Ideology,
                                               levels = c("All left", "Left", "Center", "Right", "All right"))


Ideology_data_acmes.better_pol$type <- "Acmes"
Ideology_data_mm.better_pol$type <- "Marginal Means"


Ideology_data_acmes.better_pol$labels_score2 <- as.numeric(paste0(Ideology_data_acmes.better_pol$labels_score, ".", Ideology_data_acmes.better_pol$Ideology_score))
Ideology_data_mm.better_pol$labels_score2 <- as.numeric(paste0(Ideology_data_mm.better_pol$labels_score, ".", Ideology_data_mm.better_pol$Ideology_score))


## Create data Figure A20




acmes.prob_vote_ideology <- rbind(acmes.prob_vote_all_left, acmes.prob_vote_left, acmes.prob_vote_center, acmes.prob_vote_right, acmes.prob_vote_all_right)
mm.prob_vote_ideology <- rbind(mm.prob_vote_all_left, mm.prob_vote_left, mm.prob_vote_center, mm.prob_vote_right, mm.prob_vote_all_right)



Ideology_data_acmes.prob_vote <- as.data.frame(list(labels = rep(c("Age", "33", "43", "53", "63", "73",
                                                                   "Profession", "Buisness Person", "Farmer", "Lawyer", "Medical doctor", "Parliamentary assistant",
                                                                   "Career", "Joined party 3 years ago", "Party offices in last 15 years",
                                                                   "Gender", "Man", "Woman",
                                                                   "Legislative Effectiveness", "Successful in parliament", "Not very successful in parliament",
                                                                   "Presence in Constituency", "Rarely in constituency", "Often in constituency",
                                                                   "Knowledge of voters", "Does not know voters well", "Knows voters well",
                                                                   "Social Media", "Communicates regularly", "Does not communicate often"),5),
                                                    labels_score = rep(c(13:30,1:12), 5),
                                                    estimate = c(NA, acmes.prob_vote_ideology$estimate[1:5],
                                                                 NA, acmes.prob_vote_ideology$estimate[6:10],
                                                                 NA, acmes.prob_vote_ideology$estimate[11:12],
                                                                 NA, acmes.prob_vote_ideology$estimate[13:14],
                                                                 NA, acmes.prob_vote_ideology$estimate[15:16],
                                                                 NA, acmes.prob_vote_ideology$estimate[17:18],
                                                                 NA, acmes.prob_vote_ideology$estimate[19:20],
                                                                 NA, acmes.prob_vote_ideology$estimate[21:22],
                                                                 NA, acmes.prob_vote_ideology$estimate[22+1:5],
                                                                 NA, acmes.prob_vote_ideology$estimate[22+6:10],
                                                                 NA, acmes.prob_vote_ideology$estimate[22+11:12],
                                                                 NA, acmes.prob_vote_ideology$estimate[22+13:14],
                                                                 NA, acmes.prob_vote_ideology$estimate[22+15:16],
                                                                 NA, acmes.prob_vote_ideology$estimate[22+17:18],
                                                                 NA, acmes.prob_vote_ideology$estimate[22+19:20],
                                                                 NA, acmes.prob_vote_ideology$estimate[22+21:22],
                                                                 NA, acmes.prob_vote_ideology$estimate[44+1:5],
                                                                 NA, acmes.prob_vote_ideology$estimate[44+6:10],
                                                                 NA, acmes.prob_vote_ideology$estimate[44+11:12],
                                                                 NA, acmes.prob_vote_ideology$estimate[44+13:14],
                                                                 NA, acmes.prob_vote_ideology$estimate[44+15:16],
                                                                 NA, acmes.prob_vote_ideology$estimate[44+17:18],
                                                                 NA, acmes.prob_vote_ideology$estimate[44+19:20],
                                                                 NA, acmes.prob_vote_ideology$estimate[44+21:22],
                                                                 NA, acmes.prob_vote_ideology$estimate[66+1:5],
                                                                 NA, acmes.prob_vote_ideology$estimate[66+6:10],
                                                                 NA, acmes.prob_vote_ideology$estimate[66+11:12],
                                                                 NA, acmes.prob_vote_ideology$estimate[66+13:14],
                                                                 NA, acmes.prob_vote_ideology$estimate[66+15:16],
                                                                 NA, acmes.prob_vote_ideology$estimate[66+17:18],
                                                                 NA, acmes.prob_vote_ideology$estimate[66+19:20],
                                                                 NA, acmes.prob_vote_ideology$estimate[66+21:22],
                                                                 NA, acmes.prob_vote_ideology$estimate[88+1:5],
                                                                 NA, acmes.prob_vote_ideology$estimate[88+6:10],
                                                                 NA, acmes.prob_vote_ideology$estimate[88+11:12],
                                                                 NA, acmes.prob_vote_ideology$estimate[88+13:14],
                                                                 NA, acmes.prob_vote_ideology$estimate[88+15:16],
                                                                 NA, acmes.prob_vote_ideology$estimate[88+17:18],
                                                                 NA, acmes.prob_vote_ideology$estimate[88+19:20],
                                                                 NA, acmes.prob_vote_ideology$estimate[88+21:22]),
                                                    
                                                    lower = c(NA, NA, acmes.prob_vote_ideology$lower[2:5],
                                                              NA, NA, acmes.prob_vote_ideology$lower[7:10],
                                                              NA, NA, acmes.prob_vote_ideology$lower[12],
                                                              NA, NA, acmes.prob_vote_ideology$lower[14],
                                                              NA, NA, acmes.prob_vote_ideology$lower[16],
                                                              NA, NA, acmes.prob_vote_ideology$lower[18],
                                                              NA, NA, acmes.prob_vote_ideology$lower[20],
                                                              NA, NA, acmes.prob_vote_ideology$lower[22],
                                                              NA, NA, acmes.prob_vote_ideology$lower[22+2:5],
                                                              NA, NA, acmes.prob_vote_ideology$lower[22+7:10],
                                                              NA, NA, acmes.prob_vote_ideology$lower[22+12],
                                                              NA, NA, acmes.prob_vote_ideology$lower[22+14],
                                                              NA, NA, acmes.prob_vote_ideology$lower[22+16],
                                                              NA, NA, acmes.prob_vote_ideology$lower[22+18],
                                                              NA, NA, acmes.prob_vote_ideology$lower[22+20],
                                                              NA, NA, acmes.prob_vote_ideology$lower[22+22],
                                                              NA, NA, acmes.prob_vote_ideology$lower[44+2:5],
                                                              NA, NA, acmes.prob_vote_ideology$lower[44+7:10],
                                                              NA, NA, acmes.prob_vote_ideology$lower[44+12],
                                                              NA, NA, acmes.prob_vote_ideology$lower[44+14],
                                                              NA, NA, acmes.prob_vote_ideology$lower[44+16],
                                                              NA, NA, acmes.prob_vote_ideology$lower[44+18],
                                                              NA, NA, acmes.prob_vote_ideology$lower[44+20],
                                                              NA, NA, acmes.prob_vote_ideology$lower[44+22],
                                                              NA, NA, acmes.prob_vote_ideology$lower[66+2:5],
                                                              NA, NA, acmes.prob_vote_ideology$lower[66+7:10],
                                                              NA, NA, acmes.prob_vote_ideology$lower[66+12],
                                                              NA, NA, acmes.prob_vote_ideology$lower[66+14],
                                                              NA, NA, acmes.prob_vote_ideology$lower[66+16],
                                                              NA, NA, acmes.prob_vote_ideology$lower[66+18],
                                                              NA, NA, acmes.prob_vote_ideology$lower[66+20],
                                                              NA, NA, acmes.prob_vote_ideology$lower[66+22],
                                                              NA, NA, acmes.prob_vote_ideology$lower[88+2:5],
                                                              NA, NA, acmes.prob_vote_ideology$lower[88+7:10],
                                                              NA, NA, acmes.prob_vote_ideology$lower[88+12],
                                                              NA, NA, acmes.prob_vote_ideology$lower[88+14],
                                                              NA, NA, acmes.prob_vote_ideology$lower[88+16],
                                                              NA, NA, acmes.prob_vote_ideology$lower[88+18],
                                                              NA, NA, acmes.prob_vote_ideology$lower[88+20],
                                                              NA, NA, acmes.prob_vote_ideology$lower[88+22]),
                                                    upper = c(NA, NA, acmes.prob_vote_ideology$upper[2:5],
                                                              NA, NA, acmes.prob_vote_ideology$upper[7:10],
                                                              NA, NA, acmes.prob_vote_ideology$upper[12],
                                                              NA, NA, acmes.prob_vote_ideology$upper[14],
                                                              NA, NA, acmes.prob_vote_ideology$upper[16],
                                                              NA, NA, acmes.prob_vote_ideology$upper[18],
                                                              NA, NA, acmes.prob_vote_ideology$upper[20],
                                                              NA, NA, acmes.prob_vote_ideology$upper[22],
                                                              NA, NA, acmes.prob_vote_ideology$upper[22+2:5],
                                                              NA, NA, acmes.prob_vote_ideology$upper[22+7:10],
                                                              NA, NA, acmes.prob_vote_ideology$upper[22+12],
                                                              NA, NA, acmes.prob_vote_ideology$upper[22+14],
                                                              NA, NA, acmes.prob_vote_ideology$upper[22+16],
                                                              NA, NA, acmes.prob_vote_ideology$upper[22+18],
                                                              NA, NA, acmes.prob_vote_ideology$upper[22+20],
                                                              NA, NA, acmes.prob_vote_ideology$upper[22+22],
                                                              NA, NA, acmes.prob_vote_ideology$upper[44+2:5],
                                                              NA, NA, acmes.prob_vote_ideology$upper[44+7:10],
                                                              NA, NA, acmes.prob_vote_ideology$upper[44+12],
                                                              NA, NA, acmes.prob_vote_ideology$upper[44+14],
                                                              NA, NA, acmes.prob_vote_ideology$upper[44+16],
                                                              NA, NA, acmes.prob_vote_ideology$upper[44+18],
                                                              NA, NA, acmes.prob_vote_ideology$upper[44+20],
                                                              NA, NA, acmes.prob_vote_ideology$upper[44+22],
                                                              NA, NA, acmes.prob_vote_ideology$upper[66+2:5],
                                                              NA, NA, acmes.prob_vote_ideology$upper[66+7:10],
                                                              NA, NA, acmes.prob_vote_ideology$upper[66+12],
                                                              NA, NA, acmes.prob_vote_ideology$upper[66+14],
                                                              NA, NA, acmes.prob_vote_ideology$upper[66+16],
                                                              NA, NA, acmes.prob_vote_ideology$upper[66+18],
                                                              NA, NA, acmes.prob_vote_ideology$upper[66+20],
                                                              NA, NA, acmes.prob_vote_ideology$upper[66+22],
                                                              NA, NA, acmes.prob_vote_ideology$upper[88+2:5],
                                                              NA, NA, acmes.prob_vote_ideology$upper[88+7:10],
                                                              NA, NA, acmes.prob_vote_ideology$upper[88+12],
                                                              NA, NA, acmes.prob_vote_ideology$upper[88+14],
                                                              NA, NA, acmes.prob_vote_ideology$upper[88+16],
                                                              NA, NA, acmes.prob_vote_ideology$upper[88+18],
                                                              NA, NA, acmes.prob_vote_ideology$upper[88+20],
                                                              NA, NA, acmes.prob_vote_ideology$upper[88+22]),
                                                    Ideology = rep(c("All left", "Left", "Center", "Right", "All right"), each=30),
                                                    Ideology_score = rep(c(0:4), each=30)))



Ideology_data_mm.prob_vote <- as.data.frame(list(labels = rep(c("Age", "33", "43", "53", "63", "73",
                                                                "Profession", "Buisness Person", "Farmer", "Lawyer", "Medical doctor", "Parliamentary assistant",
                                                                "Career", "Joined party 3 years ago", "Party offices in last 15 years",
                                                                "Gender", "Man", "Woman",
                                                                "Legislative Effectiveness", "Successful in parliament", "Not very successful in parliament",
                                                                "Presence in Constituency", "Rarely in constituency", "Often in constituency",
                                                                "Knowledge of voters", "Does not know voters well", "Knows voters well",
                                                                "Social Media", "Communicates regularly", "Does not communicate often"),5),
                                                 labels_score = rep(c(13:30,1:12), 5),
                                                 estimate = c(NA, mm.prob_vote_ideology$estimate[1:5],
                                                              NA, mm.prob_vote_ideology$estimate[6:10],
                                                              NA, mm.prob_vote_ideology$estimate[11:12],
                                                              NA, mm.prob_vote_ideology$estimate[13:14],
                                                              NA, mm.prob_vote_ideology$estimate[15:16],
                                                              NA, mm.prob_vote_ideology$estimate[17:18],
                                                              NA, mm.prob_vote_ideology$estimate[19:20],
                                                              NA, mm.prob_vote_ideology$estimate[21:22],
                                                              NA, mm.prob_vote_ideology$estimate[22+1:5],
                                                              NA, mm.prob_vote_ideology$estimate[22+6:10],
                                                              NA, mm.prob_vote_ideology$estimate[22+11:12],
                                                              NA, mm.prob_vote_ideology$estimate[22+13:14],
                                                              NA, mm.prob_vote_ideology$estimate[22+15:16],
                                                              NA, mm.prob_vote_ideology$estimate[22+17:18],
                                                              NA, mm.prob_vote_ideology$estimate[22+19:20],
                                                              NA, mm.prob_vote_ideology$estimate[22+21:22],
                                                              NA, mm.prob_vote_ideology$estimate[44+1:5],
                                                              NA, mm.prob_vote_ideology$estimate[44+6:10],
                                                              NA, mm.prob_vote_ideology$estimate[44+11:12],
                                                              NA, mm.prob_vote_ideology$estimate[44+13:14],
                                                              NA, mm.prob_vote_ideology$estimate[44+15:16],
                                                              NA, mm.prob_vote_ideology$estimate[44+17:18],
                                                              NA, mm.prob_vote_ideology$estimate[44+19:20],
                                                              NA, mm.prob_vote_ideology$estimate[44+21:22],
                                                              NA, mm.prob_vote_ideology$estimate[66+1:5],
                                                              NA, mm.prob_vote_ideology$estimate[66+6:10],
                                                              NA, mm.prob_vote_ideology$estimate[66+11:12],
                                                              NA, mm.prob_vote_ideology$estimate[66+13:14],
                                                              NA, mm.prob_vote_ideology$estimate[66+15:16],
                                                              NA, mm.prob_vote_ideology$estimate[66+17:18],
                                                              NA, mm.prob_vote_ideology$estimate[66+19:20],
                                                              NA, mm.prob_vote_ideology$estimate[66+21:22],
                                                              NA, mm.prob_vote_ideology$estimate[88+1:5],
                                                              NA, mm.prob_vote_ideology$estimate[88+6:10],
                                                              NA, mm.prob_vote_ideology$estimate[88+11:12],
                                                              NA, mm.prob_vote_ideology$estimate[88+13:14],
                                                              NA, mm.prob_vote_ideology$estimate[88+15:16],
                                                              NA, mm.prob_vote_ideology$estimate[88+17:18],
                                                              NA, mm.prob_vote_ideology$estimate[88+19:20],
                                                              NA, mm.prob_vote_ideology$estimate[88+21:22]),
                                                 
                                                 lower = c(NA, mm.prob_vote_ideology$lower[1:5],
                                                           NA, mm.prob_vote_ideology$lower[6:10],
                                                           NA, mm.prob_vote_ideology$lower[11:12],
                                                           NA, mm.prob_vote_ideology$lower[13:14],
                                                           NA, mm.prob_vote_ideology$lower[15:16],
                                                           NA, mm.prob_vote_ideology$lower[17:18],
                                                           NA, mm.prob_vote_ideology$lower[19:20],
                                                           NA, mm.prob_vote_ideology$lower[21:22],
                                                           NA, mm.prob_vote_ideology$lower[22+1:5],
                                                           NA, mm.prob_vote_ideology$lower[22+6:10],
                                                           NA, mm.prob_vote_ideology$lower[22+11:12],
                                                           NA, mm.prob_vote_ideology$lower[22+13:14],
                                                           NA, mm.prob_vote_ideology$lower[22+15:16],
                                                           NA, mm.prob_vote_ideology$lower[22+17:18],
                                                           NA, mm.prob_vote_ideology$lower[22+19:20],
                                                           NA, mm.prob_vote_ideology$lower[22+21:22],
                                                           NA, mm.prob_vote_ideology$lower[44+1:5],
                                                           NA, mm.prob_vote_ideology$lower[44+6:10],
                                                           NA, mm.prob_vote_ideology$lower[44+11:12],
                                                           NA, mm.prob_vote_ideology$lower[44+13:14],
                                                           NA, mm.prob_vote_ideology$lower[44+15:16],
                                                           NA, mm.prob_vote_ideology$lower[44+17:18],
                                                           NA, mm.prob_vote_ideology$lower[44+19:20],
                                                           NA, mm.prob_vote_ideology$lower[44+21:22],
                                                           NA, mm.prob_vote_ideology$lower[66+1:5],
                                                           NA, mm.prob_vote_ideology$lower[66+6:10],
                                                           NA, mm.prob_vote_ideology$lower[66+11:12],
                                                           NA, mm.prob_vote_ideology$lower[66+13:14],
                                                           NA, mm.prob_vote_ideology$lower[66+15:16],
                                                           NA, mm.prob_vote_ideology$lower[66+17:18],
                                                           NA, mm.prob_vote_ideology$lower[66+19:20],
                                                           NA, mm.prob_vote_ideology$lower[66+21:22],
                                                           NA, mm.prob_vote_ideology$lower[88+1:5],
                                                           NA, mm.prob_vote_ideology$lower[88+6:10],
                                                           NA, mm.prob_vote_ideology$lower[88+11:12],
                                                           NA, mm.prob_vote_ideology$lower[88+13:14],
                                                           NA, mm.prob_vote_ideology$lower[88+15:16],
                                                           NA, mm.prob_vote_ideology$lower[88+17:18],
                                                           NA, mm.prob_vote_ideology$lower[88+19:20],
                                                           NA, mm.prob_vote_ideology$lower[88+21:22]),
                                                 upper = c(NA, mm.prob_vote_ideology$upper[1:5],
                                                           NA, mm.prob_vote_ideology$upper[6:10],
                                                           NA, mm.prob_vote_ideology$upper[11:12],
                                                           NA, mm.prob_vote_ideology$upper[13:14],
                                                           NA, mm.prob_vote_ideology$upper[15:16],
                                                           NA, mm.prob_vote_ideology$upper[17:18],
                                                           NA, mm.prob_vote_ideology$upper[19:20],
                                                           NA, mm.prob_vote_ideology$upper[21:22],
                                                           NA, mm.prob_vote_ideology$upper[22+1:5],
                                                           NA, mm.prob_vote_ideology$upper[22+6:10],
                                                           NA, mm.prob_vote_ideology$upper[22+11:12],
                                                           NA, mm.prob_vote_ideology$upper[22+13:14],
                                                           NA, mm.prob_vote_ideology$upper[22+15:16],
                                                           NA, mm.prob_vote_ideology$upper[22+17:18],
                                                           NA, mm.prob_vote_ideology$upper[22+19:20],
                                                           NA, mm.prob_vote_ideology$upper[22+21:22],
                                                           NA, mm.prob_vote_ideology$upper[44+1:5],
                                                           NA, mm.prob_vote_ideology$upper[44+6:10],
                                                           NA, mm.prob_vote_ideology$upper[44+11:12],
                                                           NA, mm.prob_vote_ideology$upper[44+13:14],
                                                           NA, mm.prob_vote_ideology$upper[44+15:16],
                                                           NA, mm.prob_vote_ideology$upper[44+17:18],
                                                           NA, mm.prob_vote_ideology$upper[44+19:20],
                                                           NA, mm.prob_vote_ideology$upper[44+21:22],
                                                           NA, mm.prob_vote_ideology$upper[66+1:5],
                                                           NA, mm.prob_vote_ideology$upper[66+6:10],
                                                           NA, mm.prob_vote_ideology$upper[66+11:12],
                                                           NA, mm.prob_vote_ideology$upper[66+13:14],
                                                           NA, mm.prob_vote_ideology$upper[66+15:16],
                                                           NA, mm.prob_vote_ideology$upper[66+17:18],
                                                           NA, mm.prob_vote_ideology$upper[66+19:20],
                                                           NA, mm.prob_vote_ideology$upper[66+21:22],
                                                           NA, mm.prob_vote_ideology$upper[88+1:5],
                                                           NA, mm.prob_vote_ideology$upper[88+6:10],
                                                           NA, mm.prob_vote_ideology$upper[88+11:12],
                                                           NA, mm.prob_vote_ideology$upper[88+13:14],
                                                           NA, mm.prob_vote_ideology$upper[88+15:16],
                                                           NA, mm.prob_vote_ideology$upper[88+17:18],
                                                           NA, mm.prob_vote_ideology$upper[88+19:20],
                                                           NA, mm.prob_vote_ideology$upper[88+21:22]),
                                                 Ideology = rep(c("All left", "Left", "Center", "Right", "All right"), each=30),
                                                 Ideology_score = rep(c(0:4), each=30)))


Ideology_data_acmes.prob_vote$Ideology <- factor(Ideology_data_acmes.prob_vote$Ideology,
                                                 levels = c("All left", "Left", "Center", "Right", "All right"))

Ideology_data_mm.prob_vote$Ideology <- factor(Ideology_data_mm.prob_vote$Ideology,
                                              levels = c("All left", "Left", "Center", "Right", "All right"))


Ideology_data_acmes.prob_vote$type <- "Acmes"
Ideology_data_mm.prob_vote$type <- "Marginal Means"



Ideology_data_acmes.prob_vote$labels_score2 <- as.numeric(paste0(Ideology_data_acmes.prob_vote$labels_score, ".", Ideology_data_acmes.prob_vote$Ideology_score))
Ideology_data_mm.prob_vote$labels_score2 <- as.numeric(paste0(Ideology_data_mm.prob_vote$labels_score, ".", Ideology_data_mm.prob_vote$Ideology_score))


## Plot Figure A18

png("Figures/Figure A18.png", width = 2500, height = 3000, res=300)
ggplot(rbind(Ideology_data_acmes.vote_choice, Ideology_data_mm.vote_choice))+
  geom_point(aes(x=estimate, y=labels_score2, color = Ideology))+
  geom_errorbarh(aes(xmin = lower, xmax=upper, color = Ideology, y=labels_score2), height=0.1)+
  scale_y_continuous(breaks = c(1:30), labels = unique(as.character(Ideology_data_acmes.vote_choice$labels))[c(19:30,1:18)],
                     trans = "reverse")+
  scale_color_manual(values = c("red", "orange", "grey", "lightblue", "blue"))+
  ylab("")+
  facet_wrap(~type,
             labeller = labeller(
               type = c(`Marginal Means` = "Marginal Means", `Acmes` = "AverIdeology Marginal Component Effect")
             ), scales = 'free_x')+
  ylab("")+
  theme_minimal()+
  theme(legend.position = "bottom", 
        panel.border = element_rect(colour = "black", fill=NA, linewidth=.5), 
        axis.text.y = element_text(face = c("bold", rep("plain", 2), 
                                            "bold", rep("plain", 2),
                                            "bold", rep("plain", 2),
                                            "bold", rep("plain", 2),
                                            "bold", rep("plain", 5),
                                            "bold", rep("plain", 5),
                                            "bold", rep("plain", 2),
                                            "bold", rep("plain", 2))))
dev.off()

## Plot Figure A19


png("Figures/Figure A19.png", width = 2500, height = 3000, res=300)
ggplot(rbind(Ideology_data_acmes.better_pol, Ideology_data_mm.better_pol))+
  geom_point(aes(x=estimate, y=labels_score2, color = Ideology))+
  geom_errorbarh(aes(xmin = lower, xmax=upper, color = Ideology, y=labels_score2), height=0.1)+
  scale_y_continuous(breaks = c(1:30), labels = unique(as.character(Ideology_data_acmes.better_pol$labels))[c(19:30,1:18)],
                     trans = "reverse")+
  scale_color_manual(values = c("red", "orange", "grey", "lightblue", "blue"))+
  ylab("")+
  facet_wrap(~type,
             labeller = labeller(
               type = c(`Marginal Means` = "Marginal Means", `Acmes` = "AverIdeology Marginal Component Effect")
             ), scales = 'free_x')+
  ylab("")+
  theme_minimal()+
  theme(legend.position = "bottom", 
        panel.border = element_rect(colour = "black", fill=NA, linewidth=.5), 
        axis.text.y = element_text(face = c("bold", rep("plain", 2), 
                                            "bold", rep("plain", 2),
                                            "bold", rep("plain", 2),
                                            "bold", rep("plain", 2),
                                            "bold", rep("plain", 5),
                                            "bold", rep("plain", 5),
                                            "bold", rep("plain", 2),
                                            "bold", rep("plain", 2))))
dev.off()



## Plot Figure A20

png("Figures/Figure A20.png", width = 2500, height = 3000, res=300)
ggplot(rbind(Ideology_data_acmes.prob_vote, Ideology_data_mm.prob_vote))+
  geom_point(aes(x=estimate, y=labels_score2, color = Ideology))+
  geom_errorbarh(aes(xmin = lower, xmax=upper, color = Ideology, y=labels_score2), height=0.1)+
  scale_y_continuous(breaks = c(1:30), labels = unique(as.character(Ideology_data_acmes.prob_vote$labels))[c(19:30,1:18)],
                     trans = "reverse")+
  scale_color_manual(values = c("red", "orange", "grey", "lightblue", "blue"))+
  ylab("")+
  facet_wrap(~type,
             labeller = labeller(
               type = c(`Marginal Means` = "Marginal Means", `Acmes` = "AverIdeology Marginal Component Effect")
             ), scales = 'free_x')+
  ylab("")+
  theme_minimal()+
  theme(legend.position = "bottom", 
        panel.border = element_rect(colour = "black", fill=NA, linewidth=.5), 
        axis.text.y = element_text(face = c("bold", rep("plain", 2), 
                                            "bold", rep("plain", 2),
                                            "bold", rep("plain", 2),
                                            "bold", rep("plain", 2),
                                            "bold", rep("plain", 5),
                                            "bold", rep("plain", 5),
                                            "bold", rep("plain", 2),
                                            "bold", rep("plain", 2))))
dev.off()

